using Unity.Entities;
using UnityEngine;

public class PlayerMovementAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
    public float moveSpeed = 5f; // 可以在 Inspector 中设置
    public Animator animator; // 在 Inspector 中拖动 Animator 组件
    public SpriteRenderer sprite;
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        // 确保在转换时添加 PlayerMovementComponent
        dstManager.AddComponentData(entity, new PlayerMovementComponent { moveSpeed = moveSpeed });

        // 创建 Animator 实体
        dstManager.AddComponentObject(entity, animator);
        Entity animatorEntity = conversionSystem.GetPrimaryEntity(animator);
        dstManager.AddComponentData(entity, new AnimatorComponent { AnimatorEntity = animatorEntity });


        //创建 SpritrRenderer 实体

        dstManager.AddComponentObject(entity,sprite);
        Entity fliyEntity=conversionSystem.GetPrimaryEntity(sprite);
        dstManager.AddComponentData(entity, new SpriteRendererComponent { fliyEntity = fliyEntity });
        
    }
}
